/**
 * Created by Elsa on 2017/8/30.
 */
layui.define(['form', 'layedit', 'laydate','jquery'], function(exports){
    var form = layui.form(),
        $ = layui.jquery,
        layer = layui.layer,
        layedit = layui.layedit,
        laydate = layui.laydate;

    var inspnum = getQueryString("inspnum");
    console.log(tampdata);

    form.render();

    form.on('select(type)', function(data){
        if(data.value == '报检单填写有误'){
            $('#confrimlabel').html("");
            $('input[name="confirmtime"]').hide();
            form.render();
        } else{
            $('#confrimlabel').html("确认检验时间");
            $('input[name="confirmtime"]').show();
            form.render();
        }
    });

    //自定义验证规则
    form.verify({
        title: function(value) {
            if(value.length < 5) {
                return '标题至少得5个字符啊';
            }
        },
        pass: [/(.+){6,12}$/, '密码必须6到12位'],
        content: function(value) {
            layedit.sync(editIndex);
        }
    });

    //监听提交
    form.on('submit(caseglyx)', function(data) {
        $(this).attr('disabled','disabled');
        var ConstYcsConfirm = new Object();
        ConstYcsConfirm.inspnum = inspnum;
        ConstYcsConfirm.inspdate = tampdata;
        ConstYcsConfirm.status = data.field.status;
        if(ConstYcsConfirm.status=="报检单填写有误"){
            ConstYcsConfirm.confirmtime = "";
        }else{
            ConstYcsConfirm.confirmtime = data.field.confirmtime;
        }
        ConstYcsConfirm.ycs1 = data.field.ycs1;

        console.log(JSON.stringify(ConstYcsConfirm));

        $.ajax({
            type:"PUT",
            url:contextPath+"/project/const/inspdclr/update/ycsconfirm",
            contentType: "application/json; charset=utf-8",
            data:JSON.stringify(ConstYcsConfirm),
            dataType:"json",
            success:function (data) {
                console.log(data.message);
                if(data.message == "更新成功!"){
                    layer.msg('建造检验报检单已确认!<br>页面将在1秒后刷新...');
                    setTimeout(function(){window.location.reload();},1000);
                } else {
                    $('#suresubmitx').attr('disabled',false);
                    layer.msg(data.message, {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }
            },
            error:function (e) {
            }
        });
        return false;
    });

    exports('ConstYcsConfirm', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});